package com.qf.day2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @date 2022/3/25
 * @desc
 *
 * 1.  get 和  post 的请求方式
 *
 * 2. request 代表请求对象  所有请求数据 都封装到这个对象中了，想要获取请求的数据只需要调用
 * 对应的方法即可
 *   request.getXxx()
 */
@WebServlet("/request1")
public class Request1Demo extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取请求参数
        String username = req.getParameter("username");
        System.out.println(username);


        String remoteAddr = req.getRemoteAddr();  // 获取客户端的ip地址
        System.out.println(remoteAddr);
        int remotePort = req.getRemotePort(); // 获取 客户端和服务端通信的端口
        System.out.println(remotePort);

        String method = req.getMethod();   // 获取客户端的请求方式
        System.out.println(method);

    }
}
